package com.shanzmoo.db.store.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 库存实时明细
 * </p>
 *
 * @author fs
 * @since 2021-03-09
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("store_stock")
public class StoreStockEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 自增ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 商品sku
     */
    private String sku;

    /**
     * 仓库编码
     */
    private String storeCode;

    /**
     * 实时库存数量
     */
    private Integer skuNum;

    /**
     * 库存预警数量，为0时不做库存预警
     */
    private Integer alarmNum;

    /**
     * 版本号（乐观锁）
     */
    private Integer versionId;

    /**
     * 创建人
     */
    private Integer createUser;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 逻辑删除，0-未删除 1-已删除
     */
    private Boolean deleted;


    public static StoreStockEntity createInitVersion(String sku, String storeCode, Integer currentUserId) {
        StoreStockEntity stockEntity = new StoreStockEntity();
        stockEntity.setSku(sku);
        stockEntity.setStoreCode(storeCode);
        stockEntity.setSkuNum(0);
        stockEntity.setVersionId(0);
        stockEntity.setCreateUser(currentUserId);

        return stockEntity;
    }
}
